package com.sky.mapper;

import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id查询套餐中菜品id
     * @param ids
     * @return
     */
    List<Long> getSetmealIdsByDishIds(List<Long> ids);

    /**
     * 批量保存套餐菜品关系
     * @param setmealDishes
     */
    void insertBatch(List<SetmealDish>setmealDishes);

    /**
     * 通过套餐菜品表中套餐id删除关联
     * @param ids
     */
    void deleteBySetmealIds(List<Long> ids);

    /**
     * 根据套餐id获取套餐菜品关系
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> getBySetmealId(Long setmealId);

    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select d.* from dish as d left join setmeal_dish as s on s.dish_id = d.id " +
            "where s.setmeal_id = #{setmealId}")
    List<Dish> getDishesBySetmealId(Long setmealId);
}
